<!doctype html>
<html lang="en"><head>
    <meta charset="utf-8">
    <title>填写借款申请</title>
    <link rel="shortcut icon" href="/static/favicon.ico">
    <link rel="stylesheet" href="/static/front/fonts/iconfont.css">
    <link rel="stylesheet" href="/static/front/css/base_new.css">
    <link rel="stylesheet" href="/static/front/css/main.css">
    <link rel="stylesheet" href="/static/front/css/share.css">
    <script src="/static/front/js/jquery-1.11.1.min.js"></script>
    <script src="/static/front/js/js.js"></script>
</head>
<body bgcolor="#f5f5f5">
<div class="content">
	<#include "../base/top.ftl" />
    <div class="Loan-application">
       <div class="Application-steps"></div>
       <div class="fill-Apply">
       		<#if user?exists & user.realname?exists>
                <input name="loan_name" id="loan_name" type="hidden"  readonly="readonly" value="${user.realname}">
            <#else>
            	<input name="loan_name" id="loan_name" type="hidden"  readonly="readonly" placeholder="请先登录进行实名认证">
            </#if>
            <div class="fill-Apply-content">
                <h3><span>填写申请</span></h3>
               <form action="">
                   <label>
                       <span>借款金额</span>
                       <input type="text" name="amount" id="amount" placeholder="请输入借款金额" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" onblur="check()"/><em>元</em>
                   </label>
                   <label>
                       <span>借款类型</span>
                       <select name="applyType" id="applyType" disabled="disabled">
							<#if productList?exists>
								<#list productList as product>
									<option value="${product.id}" <#if (type?? & type==product.id)>selected="selected"</#if>>${product.name}</option>
								</#list>
							</#if>
                       </select>
                       <!--<i>&gt;</i>-->
                   </label>
                   <label>
                       <span>借款期限</span>
                       <select name="dateline" id="dateline">
                           <option value="1">1个月</option>
                           <option value="2">2个月</option>
                           <option value="3">3个月</option>
                           <option value="4">4个月</option>
                           <option value="5">5个月</option>
                           <option value="6">6个月</option>
                           <option value="7">7个月</option>
                           <option value="8">8个月</option>
                           <option value="9">9个月</option>
                           <option value="10">10个月</option>
                           <option value="11">11个月</option>
                           <option value="12">12个月</option>
                       </select>
                       <!--<i>&gt;</i>-->
                       <input type="checkbox" id="dateUtil" name="dateUtil" value="DAY" style="width:25px;height:14px;margin:0px;padding:0px;border:none;"/>按天
                   </label>
                   <label>
                       <span>借款用途</span>
                       <textarea placeholder="请输入您借款的意图，字数在200字以内" id="use"></textarea>
                   </label>
                   <input class="fill-Apply-btn" type="button" name="" value="提交申请" style="cursor:pointer;">
               </form>     
            </div>
       </div>
    </div>
    <!-- 尾部开始 -->
    <div id="footer">
        <div class="content">
           <#include "../base/foot.ftl" />
        </div>
    </div>
    <!-- 尾部结束 -->
</div>
</body>
<script type="text/javascript" src="${_front_js}/layer/layer.js"></script>
<script>
$(".fill-Apply-btn").click(function(){
	var loanName = $.trim($("#loan_name").val());
	var amount = $.trim($("#amount").val());
	var applyType = $("#applyType").find("option:selected").val();
	var date = $("#dateline").find("option:selected").val();
	var use = $.trim($("#use").val());
	var dateUtil = $.trim($("#dateUtil:checked").val());
	if(amount == ""){
		layer.alert("请输入借款金额！");
		return;
	}
	if(isNaN(amount)){
		layer.alert("借款金额输入格式不正确！");
		return;
	}
	if(applyType == ""){
		layer.alert("请选择借款类型！");
		return;
	}
	if(date == ""){
		layer.alert("请选择借款期限！");
		return;
	}
	if(use == ""){
		layer.alert("请填写借款用途！");
		return;
	}
	if(use.length > 200){
		layer.alert("借款用途字数必须在200以内！");
		return;
	}
	if(dateUtil == "") {
		dateUtil = "MONTH";
	}
	$.ajax({
		type: "post",
		dataType: "json",
        url: "/front/borrow/add",
        data:{
        	amount : amount,
        	applyType : applyType,
        	date :date,
        	use: use,
        	dateUtil:dateUtil
        },
        async: false,
        success: function(result) {
        	if(result.code == -1){
        		layer.alert("申请成功!", function(index){
				    layer.close(index);
				    window.location.reload();
				});  
        	}else{
        		layer.alert(result.msg, function(index){
				    layer.close(index);
				    if(result.code == 1){
	            		window.location.href="/login";
	            	}else if(result.code == 7){
	            		window.location.href="/account/safe";
	            	}
				});  
        	}
        }
    });
});

function check(){
	var amount = $("#amount").val();
	if(amount!=""){
		$("#amount").val(parseInt(amount));
	}
}

$("#dateUtil").click(function(){
	if($(this)[0].checked) {
		$("#dateline option").remove();
		for(var i=1;i<31;i++) {
			$("#dateline").append("<option value='"+i+"'>"+i+"天</option>");
		}
	}else {
		$("#dateline option").remove();
		for(var i=1;i<13;i++) {
			$("#dateline").append("<option value='"+i+"'>"+i+"个月</option>");
		}
	}
	
});
</script>
</html>